//网络请求
import axios from 'axios';
import AppConfig from '@/constants/AppConfig.js';

const $axios = axios;

export default function() {

    var $app_config = AppConfig();
	var $base_url = $app_config.Base_Url;
	var $post_config = $app_config.POST_Cfg;
	// 获取作品属性列表
    var $url_get_worksAttrs = $base_url + "/admin/wattr/v1/getWorksAttrs";
    // 编辑作品属性
    var $url_edit = $base_url + "/admin/wattr/v1/edit";
     // 编辑作品属性顺序
    var $url_editSort = $base_url + "/admin/wattr/v1/editSort";
    // 启用
    var $url_enable = $base_url + '/admin/wattr/v1/enable';
    // 禁用
    var $url_disable = $base_url + '/admin/wattr/v1/disable';
    //删除
    var $url_delete = $base_url + '/admin/wattr/v1/delete';

    return {
		getWorksAttrs: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_worksAttrs, {}, $post_config)
					.then(function(response) {
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
        },
        edit: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_edit, {
                    aid: params.aid,
					name: params.name, //属性名称
					boxOffice: params.hasBoxOffice, //是否有票房                    
					episodes: params.hasEpisodes, //是否有集数
					duration: params.hasDuration, //是否有片长
					strokeColor: params.strokeColor, //描边颜色
					bgColor: params.bgColor, //背景颜色
					textColor: params.textColor, //文本颜色
                }, $post_config)
					.then(function(response) {
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
        },
        enable: function(aid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_enable, {
                    aid: aid,
                }, $post_config)
					.then(function(response) {
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
        },
        disable: function(aid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_disable, {
                    aid: aid,
                }, $post_config)
					.then(function(response) {
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		delete: function(aid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_delete, {
                    aid: aid,
                }, $post_config)
					.then(function(response) {
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		editSort: function(sorts) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_editSort, {
                    sorts: sorts,
                }, $post_config)
					.then(function(response) {
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		}
    }
}